<?php

class GoodsReceipt
{    
    var $ID;
    var $posDate;
    var $itemsRec;
    var $supplier;
    var $comments;
	
    public function retrieve() 
    {
	require('../includes/DBConn.inc');
	$result = mysql_query("SELECT * FROM tblgoodsreceipt");
	return $result;        
    }
    
    public function retrieveByDate($searchVal) 
    {
	require('../includes/DBConn.inc');
	$result = mysql_query("SELECT * FROM tblgoodsreceipt WHERE PosDate = '$searchVal'");
	return $result;        
    }
    
    public function retrieveSuppliers($searchVal) 
    {
	require('../includes/DBConn.inc');
	$result = mysql_query("SELECT supplier from tblsupplier WHERE supplier LIKE '%$searchVal%'");
	return $result;        
    }
    
    public function retrieveByID($id) 
    {
	require('../includes/DBConn.inc');
	$result = mysql_query("SELECT * FROM tblgoodsreceipt WHERE ID=$id");
	$row = mysql_fetch_array($result);
	$this->ID =  $row['ID'];
	$this->posDate =  $row['PosDate'];
	$this->itemsRec =  $row['ItemsRec'];
	$this->supplier =  $row['Supplier'];
	$this->comments =  $row['Comments'];
    }
    
    public function add()
    {       
      	require('../includes/DBConn.inc');
      	$query = "INSERT INTO tblgoodsreceipt (PosDate, ItemsRec, Supplier, Comments) 
      	VALUES ('$_POST[posDate]', '$_POST[itemsRec]', '$_POST[supplier]', '$_POST[comments]')";
      	     
      	$result = mysql_query($query) or die("Error: ".mysql_error());
      	return $result;
    }
    
    public function update($id)
    {
      	 require('../includes/DBConn.inc');
      	 $query = "UPDATE tblgoodsreceipt SET company='$_POST[name]' 
      	 	   WHERE ID=$id";
      	 	   
      	 $result = mysql_query($query) or die("Error: ".mysql_error());
      	 return $result;
    }
    
    public function delete($id)
    {
    	 require('../includes/DBConn.inc');
         $result = mysql_query("DELETE FROM tblgoodsreceipt WHERE id=$id") or die(mysql_error());   
    }
    
}
?>